home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_12.lha
/
8_12
/
8_12a3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
2KB
|
63 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ reallocate the internal streambuf buffer
nt extrabuf::reallocate()
/cerr << "reallocate() invoked, dobuffering=" << dobuffering << "\n"; // DELETE
/cerr << "\tbase=" << form("%#x", base) << "\n"; // DELETE
/cerr << "\tgptr=" << form("%#x", gptr) << "\n"; // DELETE
/cerr << "\tpptr=" << form("%#x", pptr) << "\n"; // DELETE
/cerr << "\teptr=" << form("%#x", eptr) << "\n"; // DELETE
// the buffer is full
if ((gptr == base) || dobuffering)
{
int curlength = eptr - base;
int newlength = curlength + BUFSIZ;
char *obase = base;
base = new char[newlength];
if (base != NULL)
{
gptr = base + (gptr - obase);
pptr = base + (pptr - obase);
eptr = base + newlength;
memcpy(base, obase, curlength);
delete obase;
/cerr << "\t----------------\n"; // DELETE
/cerr << "\tbase=" << form("%#x", base) << "\n"; // DELETE
/cerr << "\tgptr=" << form("%#x", gptr) << "\n"; // DELETE
/cerr << "\tpptr=" << form("%#x", pptr) << "\n"; // DELETE
/cerr << "\teptr=" << form("%#x", eptr) << "\n"; // DELETE
/cerr << "\treturning 0\n"; // DELETE
return 0;
}
// the allocation failed
else
{
base = obase;
/cerr << "\treturning -1\n"; // DELETE
return EOF;
}
}
// there's some room at the beginning of the buffer
else
{
int length = pptr - gptr;
if (length > 0)
memmove(base, gptr, length);
gptr = base;
pptr = base + length;
/cerr << "\t----------------\n"; // DELETE
/cerr << "\tbase=" << form("%#x", base) << "\n"; // DELETE
/cerr << "\tgptr=" << form("%#x", gptr) << "\n"; // DELETE
/cerr << "\tpptr=" << form("%#x", pptr) << "\n"; // DELETE
/cerr << "\teptr=" << form("%#x", eptr) << "\n"; // DELETE
/cerr << "\treturning 0\n"; // DELETE
return 0;
}